<div class="wrapper">
	
	<?php $this->load->view('ucenter/sidebar');?>
	
	<div class="content">
		
		<h3>收货地址<a href="Javascript:;" data-toggle="modal" data-target="#AddAddress" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> 添加新地址</a></h3>
		
		<table class="table table-bordered">
		
			<tr>
				<th width="50px">默认</th>
				<th width="120px">收货人姓名</th>
				<th width="270px">手机号码</th>
				<th>操作</th>
			
			</tr>
			
			<?php foreach($address as $value):?>
			<tr id="bookmark_<?php //echo $bkVal->id;?>">
				<td><input type="radio" name="default" id="default" value="" /></td>
				<td><a href="<?php echo base_url(); ?>lists/item/" target="_blank"><?php echo $value->user_name; ?></a></td>
				<td></td>
				<td><a href="Javascript:;" onclick="confirmDel('','')" >删除</a></td>
			
			</tr>
			<?php endforeach; ?>

		</table>
		
	<div class="pagination"><?php //echo $this->pagination->pagination(); ?></div>
	</div><!-- content -->

</div><!-- wrapper -->

<!-- Modal -->
<div class="modal fade" id="AddAddress" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">添加地址</h4>
      </div>
      <div class="modal-body">
      	<div class="form-group">
      		<label for="">姓名</label>
      		<input type="text" name="user_name" id="user_name" class="form-control" value="" />
      		
      	</div>
      	
      	<div class="form-group">
      		<label for="">手机号码</label>
      		<input type="text" name="user_phone" id="user_phone" class="form-control" value="" />
      		
      	</div>
      	
      	<div class="form-group">
      		<label for="">收货地址</label>
      		<input type="text" name="user_address" id="user_address" class="form-control" value="" />
      		
      	</div>
      	
      	<div id="showMessage"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="submitAddress">保存</button>
      </div>
    </div>
  </div>
</div>

<script>
function confirmDel(id,name){
	
	var myModal = new jBox('Confirm', {

		confirmButton:"删除收藏",
		cancelButton:"关闭窗口",
		content:"确认删除商品收藏："+name+"？",
		confirm:function(){
			$.ajax({
				url:"<?php echo base_url();?>ucenter/deleteBookmark",
				dataType:"json",
				type:"post",
				data:{"id":id},
				success:function(e){
					if(e.status=='10000'){
						$("#bookmark_"+e.mark_id).hide();
					}
				}
			});
		}
	});
	 
	myModal.open();
}
var is_reload=false;
$("#submitAddress").click(function(){
	
	$.ajax({
		url:"<?php echo base_url(); ?>ucenter/addAdress",
		type:"post",
		dataType:"json",
		data:{"user_name":$("#user_name").val(),"user_phone":$("#user_phone").val(),"user_address":$("#user_address").val()},
		success:function(e){
			if(e.status=='10000'){
				$("#AddAddress").modal("hide");
				is_reload=true;
			}
			

		}
	});
	
});

$('#AddAddress').on('hidden.bs.modal', function (e) {
  if(is_reload==true){
  	window.location.reload();
  }
})
</script>

